<?php
/**
 * (ajax)
 */
namespace App\Admin\Ajax\ProductPickup;

use App\Models\ProductPickup\PickupOrder;
use Illuminate\Support\Facades\DB;

class PickupOrderAjax{

    public function createPickupOrderDetail($param){

        if (!$param) {
            return response()->json(['status' => false, 'message' => '数据异常!']);
        }

        list($data, $resultData, $errorsData) = checkRepeatData($param, ['psku_id','demand_month']);
        if($errorsData) return response()->json(['status' => false, 'message' => '数据重复，请核对数据']);

        try{
            DB::beginTransaction();

            foreach ($data as $key => $val){
                $pickupOrder = PickupOrder::query()->where('pickup_no',$val['pickup_no'])->first();
                if(!$pickupOrder) throw new \Exception('提货单异常!');

                echo "<pre>";
                print_r($pickupOrder);
                echo "</pre>";
                exit;
                //foreach ($pickupOrder->detail as $k => $v){
                //    $v
                //}
            }


            echo "<pre>";
            print_r('aaa');
            echo "</pre>";
            exit;
            //$orderObj->receiver()->create($receiverData);
            //$orderObj->detail()->createMany($orderDetailData);
            //if(!$orderObj) throw new \Exception('订单录入失败!');
            //Logs::logs('customer-order', "创建消费订单(自建)：{$orderNo}", $orderObj->id);

            DB::commit();
            return response()->json(['status' =>true, 'message' => '操作成功!']);

        }catch (\Exception $e){
            DB::rollBack();
            report($e);
            return response()->json(['status' => false, 'message' => $e->getMessage()]);
        }
    }
}
